package com.iwdnb.gkgz.controller;

import java.util.Date;
import java.util.List;
import java.util.concurrent.Executor;

import cn.hutool.core.date.DateUtil;
import com.iwdnb.bmnf.common.model.result.Result;
import com.iwdnb.gkgz.application.service.StockDayDataSerivce;
import com.iwdnb.gkgz.application.service.StockPoolService;
import com.iwdnb.gkgz.application.service.StockPredictionService;
import com.iwdnb.gkgz.common.model.dto.StockDayData;
import com.iwdnb.gkgz.common.model.dto.StockPredictionData;
import com.iwdnb.gkgz.common.model.dto.prediction.StockPredictionResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 股票预测
 **/
@RestController
@RequestMapping("/api/stock/prediction")
public class StockPredictionController {

    @Autowired
    private Executor executor;
    @Autowired
    private StockPoolService stockPoolService;
    @Autowired
    private StockDayDataSerivce stockDayDataSerivce;
    @Autowired
    private StockPredictionService stockPredictionService;

    //@GetMapping("/syncRealtimeData")
    //public Result<List<StockDayData>> syncRealtimeData() {
    //    return Result.getSuccessResult(stockDayDataSerivce.syncRealtimeData());
    //}

    @GetMapping("/guessTomorrow")
    public Result<List<StockPredictionData>> guessTomorrow() {

        String year = DateUtil.format(new Date(), "yyyy");
        List<StockPredictionData> predictionDataList = stockPredictionService.guessTomorrow(year);
        return Result.getSuccessResult(predictionDataList);
    }

    @GetMapping("/guessAfterTomorrow")
    public Result<List<StockPredictionData>> guessAfterTomorrow() {
        String year = DateUtil.format(new Date(), "yyyy");
        List<StockPredictionData> predictionDataList = stockPredictionService.guessAfterTomorrow(year);
        return Result.getSuccessResult(predictionDataList);
    }

    /**
     * 生成预测参数
     *
     * @return
     */
    @GetMapping("/generatePredictionParam")
    public Result<List<StockPredictionResult>> generatePredictionParam() {
        stockPredictionService.generatePredictionParam();
        return Result.getSuccessResult(null);
    }

    /**
     * 根据预测参数获取预测结果
     *
     * @return
     */
    @GetMapping("/dynamicPrediction")
    public Result<String> dynamicPrediction(int begin, String sort) {
        executor.execute(() -> {
            stockPredictionService.dynamicPrediction(begin, sort, null);
        });
        return Result.getSuccessResult(null);
    }

    /**
     * 根据预测参数获取预测结果
     *
     * @return
     */
    @GetMapping("/caculateIncomeByUUID")
    public Result<StockPredictionResult> caculateIncomeByUUID(String uuid) {
        return Result.getSuccessResult(stockPredictionService.caculateIncome(uuid));
    }

}